package num14;

/**
 * 14. 最长公共前缀
 * 三叶组解法
 */
public class Solution2 {
    public String longestCommonPrefix(String[] ss) {
        String ans = "";
        if (ss.length == 0) return ans;
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            String s = ss[0];
            if (i >= s.length()) return ans;
            char c = ss[0].charAt(i);
            for (String item : ss) {
                if (i >= item.length() || item.charAt(i) != c) return ans;
            }
            ans += String.valueOf(c);
        }
        return ans;
    }
}